package codeTop;

public class q69 {
    public int mySqrt(int x) {
        int l = 0;
        int r = x;
        while (l <= r) {
            int mid = l+(r-l)/2;
            if (mid*mid<=x&&(mid+1)*(mid+1)>=x){
                return mid;
            } else if (x < mid * mid) {
                r = mid-1;
            } else {
                l = mid+1;
            }
        }
        return l;
    }
    public int mySqrt1(int x) {
        if (x == 0) {
            return 0;
        }
        int res = (int)Math.exp(Math.log(x)/2);
        return (long) (res+1)*(res+1)<x?res:res+1;
    }

    public static void main(String[] args) {
        q69 q = new q69();
        q.mySqrt(1);
    }
}
